import React, { Component } from 'react';
import { TextInput, StyleSheet, } from 'react-native';
import { GLOBAL } from '../../../../config/global';
import { style } from '../../../../theme/style';
import ToastUtil from '../../../../utils/toast';
const scale = GLOBAL.SCALE;
export class TextareaCpt extends Component {
	constructor(props) {
		super(props);
		let { edit } = props.data || {};
		this.state = {
			edit
		}
	}

	componentWillReceiveProps (props) {
		let { edit } = props.data || {};
		this.setState({
			edit: edit || null,
		})
	}


	render () {
		let { placeholder, _writeTextFn, id, res, isEdit } = this.props.data || {};
		let { edit } = this.state;
		return (
			<TextInput
				multiline={true}
				style={styles.notgoodInput}
				placeholder={placeholder}
				placeholderTextColor={"#999"}
				maxLength={res}
				editable={isEdit == '0' ? false : true}
				defaultValue={edit}
				underlineColorAndroid='transparent'
				onChangeText={(text) => {

					if (res && text.length > res) {
						ToastUtil.showWarning(`不能超过${res}个字`);
						text = text.substr(0, res);
					}
					_writeTextFn && _writeTextFn({ id, text });
				}}
			/>)
	}
}

const styles = StyleSheet.create({
	notgoodInput: {
		paddingLeft: 13 * scale,
		paddingRight: 10 * scale,
	},
})